exceptions.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class UnpackException(Exception):
  2. """Base class for some exceptions raised while unpacking.
  3. NOTE: unpack may raise exception other than subclass of
  4. UnpackException. If you want to catch all error, catch
  5. Exception instead.
  6. """
  7. class BufferFull(UnpackException):
  8. pass
  9. class OutOfData(UnpackException):
  10. pass
  11. class FormatError(ValueError, UnpackException):
  12. """Invalid msgpack format"""
  13. class StackError(ValueError, UnpackException):
  14. """Too nested"""
  15. # Deprecated. Use ValueError instead
  16. UnpackValueError = ValueError
  17. class ExtraData(UnpackValueError):
  18. """ExtraData is raised when there is trailing data.
  19. This exception is raised while only one-shot (not streaming)
  20. unpack.
  21. """
  22. def __init__(self, unpacked, extra):
  23. self.unpacked = unpacked
  24. self.extra = extra
  25. def __str__(self):
  26. return "unpack(b) received extra data."
  27. # Deprecated. Use Exception instead to catch all exception during packing.
  28. PackException = Exception
  29. PackValueError = ValueError
  30. PackOverflowError = OverflowError